package com.suke.czx.modules.examstack.controller;

import java.util.List;
import java.util.Map;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestBody;
import com.suke.czx.modules.examstack.entity.CommentEntity;
import com.suke.czx.modules.examstack.service.CommentService;
import com.suke.czx.common.utils.PageUtils;
import com.suke.czx.common.utils.Query;
import com.suke.czx.common.utils.R;




/**
 * 
 * 
 * @author Larry
 * @email lawhw@163.com
 * @date 2018-11-01 23:17:48
 */
@RestController
@RequestMapping("/exam/comment")
public class CommentController {
    @Autowired
    private CommentService commentService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("exam:comment:list")
    public R list(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);

        List<CommentEntity> commentList = commentService.queryList(query);
        int total = commentService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(commentList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{commentId}")
    @RequiresPermissions("exam:comment:info")
    public R info(@PathVariable("commentId") Integer commentId){
			CommentEntity comment = commentService.queryObject(commentId);

        return R.ok().put("comment", comment);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("exam:comment:save")
    public R save(@RequestBody CommentEntity comment){
			commentService.save(comment);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("exam:comment:update")
    public R update(@RequestBody CommentEntity comment){
			commentService.update(comment);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("exam:comment:delete")
    public R delete(@RequestBody Integer[] commentIds){
			commentService.deleteBatch(commentIds);

        return R.ok();
    }
	
}
